package com.jt.handler;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.pojo.SysResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/3
 */
@RestControllerAdvice
public class GlobalException {


    @ExceptionHandler(RuntimeException.class)
    public Object excetption(RuntimeException e, HttpServletRequest request){
        System.out.println(e.getMessage());
        String callback = request.getParameter("callback");
        if (StringUtils.isEmpty(callback)){
            return SysResult.fail();
        }else {
            return new JSONPObject(callback, SysResult.fail());
        }
    }
}
